import { BrowserModule } from '@angular/platform-browser';
import { NgModule, Compiler, CompilerFactory, COMPILER_OPTIONS } from '@angular/core';

import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { JitCompilerFactory } from '@angular/platform-browser-dynamic';
import { ServiceWorkerModule } from '@angular/service-worker';
import { environment } from '../environments/environment';
import { RouterService } from './services/router.service';
import { ModuleService } from './services/module.service';
import { PluginsContainerComponent } from './pages/plugins-container/plugins-container.component';
import { HttpClientModule } from '@angular/common/http';

function createCompiler(fn: CompilerFactory): Compiler {
    return fn.createCompiler();
}

@NgModule({
    declarations: [
        AppComponent,
        PluginsContainerComponent
    ],
    imports: [
        BrowserModule,
        HttpClientModule,
        AppRoutingModule,
        ServiceWorkerModule.register('ngsw-worker.js', { enabled: environment.production })
    ],
    providers: [
        RouterService,
        ModuleService,
        {
            provide: COMPILER_OPTIONS,
            useValue: {},
            multi: true
        },
        {
            provide: CompilerFactory,
            useClass: JitCompilerFactory,
            deps: [COMPILER_OPTIONS]
        },
        {
            provide: Compiler,
            useFactory: createCompiler,
            deps: [CompilerFactory]
        }],
    bootstrap: [AppComponent]
})
export class AppModule { }
